import Vue from 'vue'
import App from './App'
import uView from 'uview-ui';
import globalData from 'common/globalData.vue'
import { http } from '@/utils/request/http.js'
Vue.use(uView);

Vue.config.productionTip = false
Vue.prototype.globalData = globalData
Vue.prototype.$http = http
Vue.prototype.add = function(e) {
	console.log(e)
	if (this.globalData.cardList.some(item => {
			return item.goodsId === e.goodsId
		})) {
		this.globalData.cardList.forEach((item, index) => {
			
			if (item.goodsId === e.goodsId) {
				if(e.num<= e.goodsNum){
					this.globalData.cardList[index].num = this.globalData.cardList[index].num * 1 + 1
				}else{
					
				}
				
			}
		})
	} else {
		this.globalData.cardList.push(e)
        console.log('zenjiahuibiao')
		uni.setTabBarBadge({
			index: 2,
			text: ''+ this.globalData.cardList.length
		})
	}
	
	uni.setStorage({
		key: 'cardList',
		data: this.globalData.cardList
	})

}
Vue.prototype.del = function(e,type) {
	console.log(e,type)
	if(type){
		this.globalData.cardList.forEach((item, index) => {
			if (item.goodsId === e.goodsId) {
				this.globalData.cardList.splice(index,1)
			}
			uni.setTabBarBadge({
				index: 2,
				text: ''+ this.globalData.cardList.length
			})
		})
	}else{
		this.globalData.cardList.forEach((item, index) => {
			if (item.goodsId === e.goodsId) {
				this.globalData.cardList[index].num = this.globalData.cardList[index].num * 1 - 1
			}
		})
	}
	uni.setStorage({
		key: 'cardList',
		data: this.globalData.cardList
	})
}
App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
